#include<iostream>
using namespace std;
class SeqList {
private:
	int* list;
	int maxsize;
	int size;
public:
	SeqList() {
		maxsize = 1000;
		size = 0;
		list = new int[maxsize];
	}
	~SeqList() {
		delete[] list;
	}
	void Pop(int n, int* a);
	void print();
};
void SeqList::Pop(int n, int* a) {
	for (int i = 0; i < n; i++) {
		if (size == 0) {
			list[size++] = a[i];
			continue;
		}
		if (a[i] > list[size - 1]) {
			list[size++] = a[i];
			continue;
		}
		for (int j = 0; j < size - 1; j++) {
			if (list[j] < a[i] && a[i] < list[j + 1]) {
				for (int k = size; k > j + 1; k--) {
					list[k] = list[k - 1];
				}
				list[j + 1] = a[i];
				size++;
			}
		}
	}
}
void SeqList::print() {
	cout << size << ' ';
	for (int i = 0; i < size; i++) {
		cout << list[i] << ' ';
	}
	cout << endl;
}
int main()
{
	SeqList sl;
	int n;
	cin >> n;
	int* A = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	sl.Pop(n, A);
	cin >> n;
	int* B = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> B[i];
	}
	sl.Pop(n, B);
	sl.print();

}